/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';
import React, {
    Component,
} from 'react';

import {
    StyleSheet,
    Text,
    View,
    Image,
    TouchableHighlight,
    ProgressBarAndroid,
    ProgressViewIOS,
    Platform
} from 'react-native';

import GiftedListView from 'react-native-gifted-listview';

export default class RefreshListView extends Component {
    constructor (props) {
        super(props)
    }
    
    _renderPaginationWaitingView(paginateCallback) {
        if (this.props.paginationWaitingView) {
            return this.props.paginationWaitingView(paginateCallback);
        }
        
        return (
        <TouchableHighlight 
            underlayColor='#c8c7cc'
            onPress={paginateCallback}
            style={[customStyles.paginationView,this.props.customStyles.paginationView]}
        >
            <Text style={[customStyles.actionsLabel,this.props.customStyles.actionsLabel]}>
                加载更多
            </Text>
        </TouchableHighlight>
        );
    }
    
    _renderEmptyView(refreshCallback) {
        if (this.props.emptyView) {
            return this.props.emptyView(refreshCallback);
        }
        
        return (
        <View style={[customStyles.defaultView,this.props.customStyles.defaultView]}>
            <Text style={[customStyles.defaultViewTitle,this.props.customStyles.defaultViewTitle]}>
                对不起，没有找到数据
            </Text>
            
            <TouchableHighlight 
            underlayColor='#c8c7cc'
            onPress={refreshCallback}
            >
            <Text>
                ↻
            </Text>
            </TouchableHighlight>
        </View>
        );
    }
    
    render() {
        return (
            <GiftedListView
                paginationWaitingView={this._renderPaginationWaitingView.bind(this)}
                emptyView={this._renderEmptyView.bind(this)}
                {...this.props}
            />
        );
    }
}

var customStyles = {
    actionsLabel: {
        fontSize: 20,
        color: '#007aff',
    },
    paginationView: {
        height: 44,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#FFF',
    },
    defaultView: {
      justifyContent: 'center',
      alignItems: 'center',
      padding: 20,
    },
    defaultViewTitle: {
      fontSize: 16,
      fontWeight: 'bold',
      marginBottom: 15,
    },
};
